<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <!-- <role-search @search="reload" /> -->
      <!-- 数据表格 -->
      <ele-pro-table ref="table"
                     :columns="columns"
                     :datasource="datasource"
                     :selection.sync="selection">
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>
          <el-button size="small"
                     type="primary"
                     icon="el-icon-plus"
                     class="ele-btn-icon"
                     @click="openEdit()">
            添加
          </el-button>
        </template>

        <!-- 状态列 -->

        <template v-slot:loopPicture="{ row }">
          <div class="flex">
            <img class="avaterName"
                 :src="row.img"
                 alt="" />

          </div>
        </template>

        <template v-slot:link="{ row }">
          <div>
            {{ row.link?row.link:'----' }}
          </div>
        </template>

        <template v-slot:jump_way="{ row }">
          <el-tag v-if="row.jump_way == 1"
                  type="warning">跳本地</el-tag>
          <el-tag v-if="row.jump_way == 2"
                  type="success">跳h5</el-tag>
          <el-tag v-if="row.jump_way == 3"
                  type="success">跳小程序</el-tag>
        </template>
        <template v-slot:type="{ row }">
          <el-tag v-if="row.type == 1"
                  type="warning">首页</el-tag>
          <el-tag v-if="row.type == 2"
                  type="success">商城</el-tag>
          <el-tag v-if="row.type == 3"
                  type="success">套餐卡市场</el-tag>
        </template>
        <!-- 操作列 -->
        <template v-slot:action="{ row }">
          <el-link type="primary"
                   :underline="false"
                   icon="el-icon-edit"
                   @click="openEdit(row)">
            修改
          </el-link>

          <el-popconfirm class="ele-action"
                         title="确定要删除该条记录吗？"
                         @confirm="remove(row)">
            <template v-slot:reference>
              <el-link type="danger"
                       :underline="false"
                       icon="el-icon-delete">
                删除
              </el-link>
            </template>
          </el-popconfirm>
        </template>
      </ele-pro-table>
    </el-card>

    <role-edit :data="current"
               :drawerEditBoolen.sync="drawerEditBoolen"
               @done="reload" />
    <!-- 权限分配弹窗 -->
  </div>
</template>
  
  <script>
// import RoleSearch from './components/role-search';
import RoleEdit from './components/role-edit';


import { delPoster, posterList, } from '@/api/HomePageSettings/index'
export default {
  name: 'Recharge',
  components: {
    // RoleSearch,
    RoleEdit
  },
  data () {
    return {

      // 表格列配置
      columns: [
        {
          columnKey: 'index',
          type: 'index',
          width: 45,
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'left'
        },
        {
          prop: 'loopPicture',
          label: '轮播图',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'loopPicture'
        },
        {
          prop: 'jump_way',
          label: '跳转方式',
          align: 'center',
          sortable: 'custom',
          showOverflowTooltip: true,
          slot: 'jump_way',
          minWidth: 80
        },
        {
          prop: 'link',
          label: '跳转链接',
          align: 'center',
          sortable: 'custom',
          showOverflowTooltip: false,
          slot: 'link',
          minWidth: 150
        },
        {
          prop: 'sort',
          label: '轮播图排序',
          sortable: 'custom',
          showOverflowTooltip: true,
          align: 'center',
          minWidth: 80
        },
        {
          prop: 'type',
          label: '轮播图类型',
          align: 'center',
          sortable: 'custom',
          minWidth: 80,
          resizable: false,
          showOverflowTooltip: true,
          slot: 'type'
        },
        {
          prop: 'create_time',
          label: '创建时间',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 130,
          formatter: (_row, _column, cellValue) => {
            return this.$util.toDateString(cellValue, 'yyyy-MM-dd HH:mm');
          }
        },
        {
          columnKey: 'action',
          label: '操作',

          align: 'center',

          slot: 'action',

          showOverflowTooltip: true
        }
      ],
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      drawerEditBoolen: false,
      // 是否显示导入弹窗
      showAuth: false,
      showChoose: false
    };
  },
  computed: {
    // 服务状态
    // statusType () {
    //   return function (statusType) {
    //     // console.log(applyType)
    //     if (statusType == '1') {
    //       return {
    //         status: '可服务',
    //         type: ''
    //       };
    //     } else if (statusType == '2') {
    //       return {
    //         status: '服务中',
    //         type: 'success'
    //       };
    //     } else if (statusType == '3') {
    //       return {
    //         status: '已冻结',
    //         type: 'danger'
    //       };
    //     } else {
    //       return {
    //         status: '离线中',
    //         type: 'info'
    //       };
    //     }
    //   };
    // },
  },
  activated () {
    this.reload()
  },
  methods: {
    /* 表格数据源 */
    datasource ({ page, limit, where, }) {
      return posterList({
        page,
        limit,
        ...where,

      });
    },
    /* 刷新表格 */
    reload (where) {
      this.$refs.table.reload({ page: 1, where: where });
    },
    /* 显示编辑 */
    async openEdit (row) {
      console.log(row);
      if (row?.id) {

        this.current = row;
        // 用户余额管理
        this.drawerEditBoolen = !this.drawerEditBoolen;
      } else {
        this.drawerEditBoolen = !this.drawerEditBoolen;
        this.current = null;
      }
    },



    /* 显示分配权限 */
    openAuth (row) {
      this.current = row;
      this.showAuth = true;
    },
    /* 删除 */
    remove (row) {
      const loading = this.$loading({ lock: true });
      delPoster({
        id: row.id
      })
        .then((msg) => {
          loading.close();
          this.$message.success(msg);
          this.reload();
        })
        .catch((e) => {
          loading.close();
          this.$message.error(e.message);
        });
    }
  }
};
  </script>
  
  <style lang="less">
.avaterName {
  width: 52px;
  height: 52px;

  vertical-align: middle;
  margin-right: 5px;
}
</style>
  